package com.stm.web.controller.basicData;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stm.basicData.domain.KfToolsType;
import com.stm.basicData.domain.ToolsModel;
import com.stm.basicData.service.IToolsModelService;
import com.stm.basicData.service.KfToolsTypeService;
import com.stm.common.annotation.Log;
import com.stm.common.core.controller.BaseController;
import com.stm.common.core.domain.AjaxResult;
import com.stm.common.core.page.TableDataInfo;
import com.stm.common.enums.BusinessType;
import com.stm.common.utils.poi.ExcelUtil;
import com.stm.framework.util.ShiroUtils;

/**
 * 工具规格型号 信息操作处理
 * 
 * @author wyc
 * @date 2019-04-10
 */
@Controller
@RequestMapping("/basicData/toolsModel")
public class ToolsModelController extends BaseController
{
    private String prefix = "basicData/toolsModel";
	
	@Autowired
	private IToolsModelService toolsModelService;

	@Autowired
	private KfToolsTypeService kfToolsTypeService;

	@RequiresPermissions("basicData:toolsModel:view")
	@GetMapping()
	public String toolsModel(ModelMap mmap)
    {
    	mmap.put("user", ShiroUtils.getSysUser());
	    return prefix + "/toolsModel";
	}
	
	/**
	 * 查询工具规格型号列表
	 */
	@RequiresPermissions("basicData:toolsModel:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ToolsModel toolsModel)
	{
		startPage();
        List<ToolsModel> list = toolsModelService.selectToolsModelList(toolsModel);
		return getDataTable(list);
	}



	/**
	 * 导出工具规格型号列表
	 */
	@RequiresPermissions("basicData:toolsModel:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ToolsModel toolsModel)
    {
    	List<ToolsModel> list = toolsModelService.selectToolsModelList(toolsModel);
        ExcelUtil<ToolsModel> util = new ExcelUtil<ToolsModel>(ToolsModel.class);
        return util.exportExcel(list, "toolsModel");
    }
	
	/**
	 * 新增工具规格型号
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存工具规格型号
	 */
	@RequiresPermissions("basicData:toolsModel:add")
	@Log(title = "工具规格型号", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ToolsModel toolsModel)
	{
		toolsModel.setCreateBy(ShiroUtils.getLoginName());
		toolsModel.setDprtcode(ShiroUtils.getSysUser().getDeptId());
		return toAjax(toolsModelService.insertToolsModel(toolsModel));
	}

	/**
	 * 修改工具规格型号
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		ToolsModel toolsModel = toolsModelService.selectToolsModelById(id);
		mmap.put("toolsModel", toolsModel);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存工具规格型号
	 */
	@RequiresPermissions("basicData:toolsModel:edit")
	@Log(title = "工具规格型号", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ToolsModel toolsModel)
	{
		toolsModel.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(toolsModelService.updateToolsModel(toolsModel));
	}
	
	/**
	 * 删除工具规格型号
	 */
	@RequiresPermissions("basicData:toolsModel:remove")
	@Log(title = "工具规格型号", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(toolsModelService.deleteToolsModelByIds(ids));
	}

    /**
     *
     * @Description 初始化型号规格
     * @CreateTime 2019年4月8日 上午11:22:58
     * @CreateBy wyc
     * @param user
     * @return
     */
    @PostMapping("/initToolsModel")
    @ResponseBody
    public List<ToolsModel> initToolsModel(ToolsModel toolsModel)
    {
        return  toolsModelService.selectToolsModelList(toolsModel);
    }


}
